/**
 * All Rights Reserved , Copyright (C) 2023 , 青岛鼎信通讯股份有限公司
 *
 *AppUserSearchRecordsController
 * 用户搜索记录
 *
 * 修改纪录
 * 2023-08-25 版本：1.0 wuyuyang 创建。
 * @version 版本：1.0
 * @author 作者：wuyuyang
 * 创建日期：2023-08-25
 */

package com.topscomm.appv2.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.topscomm.appv2.pojo.AppUserSearchRecordsEntity;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.util.ConvertUtil;
import org.springframework.web.bind.annotation.*;

import com.topscomm.appv2.controller.auto.AppUserSearchRecordsControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: wuyuyang
 * @date: 2023-08-25
 * @description:用户搜索记录Controller
 * @modify:
 */
@RestController
@RequestMapping("appv2/appUserSearchRecords")
public class AppUserSearchRecordsController extends AppUserSearchRecordsControllerAuto implements IAppUserSearchRecordsController {
	/**
	 * @author: wuyuyang
	 * @date: 2023-08-25
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		// 参照列表多选查询
		if (paraMap.containsKey("qry_fieldkey") && paraMap.containsKey("qry_keys")) {
			String fieldKey = paraMap.get("qry_fieldkey").toString();
			String keys = paraMap.get("qry_keys").toString();
			if (!StringUtil.isEmpty(fieldKey) && !StringUtil.isEmpty(keys)) {
				sql.appendSingle(" and {0} in ({1})", fieldKey, keys);
			}
		}
		return sql.toString();
	}

	/**
	 * @author: wuyuyang
	 * @date: 2023-08-25
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}



	/**
	 * @Description:    查询搜索记录
	 * @Author:         wuyuyang
	 * @Return:         com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @exception:
	 * @Date:           25/8/2023 上午10:28
	 * @Version:        1.0
	 **/
	@GetMapping(value = "/querySearchRecord")
	public ResponseResult<Object> querySearchRecord(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			paraMap = BaseUtil.decodeSecureMap(paraMap);
			List<AppUserSearchRecordsEntity> list = this.service.querySearchRecord(paraMap);
			Map<String, Object> resultMap = new HashMap<>();
			resultMap.put("dataList", list);
			return ResponseResult.ok(resultMap);
		}catch (Exception ex) {
			return handleControllerException(ex);
		}
	}


	/**
	 * @Description:    删除指定用户指定分类的搜索记录
	 * @Author:         wuyuyang
	 * @Return:         com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @exception:
	 * @Date:           25/8/2023 上午10:58
	 * @Version:        1.0
	 **/
	@PostMapping(value = "/deleteByUserAndRecordtype")
	public ResponseResult<Object> deleteByUserAndRecordtype(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			paraMap = BaseUtil.decodeSecureMap(paraMap);
			this.service.deleteByUserAndRecordtype(paraMap);
			return ResponseResult.ok("删除成功");
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}



	/**
	 * @Description:    记录模块搜索记录
	 * @Author:         wuyuyang
	 * @Return:         com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @exception:
	 * @Date:           25/8/2023 上午11:10
	 * @Version:        1.0
	 **/
	@PostMapping(value = "/insertSearchRecord")
	public ResponseResult<Object> insertSearchRecord(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			this.service.insertSearchRecord(paraMap);
			return ResponseResult.ok("保存成功");
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}

}

